<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .touchBox{
        width: 300px;
        height: 300px;
        background: #ccc;
        position: absolute;
    }
    </style>
    <script>
    window.onload=function(){
        let box=document.getElementsByClassName('touchBox')[0];
        box.addEventListener('touchstart',function (ev) {
            let disx=ev.targetTouches[0].pageX-box.offsetLeft;
            let disy=ev.targetTouches[0].pageY-box.offsetTop;
            console.log(disx,disy)
            function fnMove(ev){
                box.style.left=ev.targetTouches[0].pageX-disx+'px';
                box.style.top=ev.targetTouches[0].pageY-disy+'px';
                // console.log('移动了',ev.targetTouches[0].pageX-disx+'px',ev.targetTouches[0].pageY-disy+'px')
            }
            function fnEnd(e){
                box.removeEventListener('touchmove',fnMove,false)
                box.removeEventListener('touchend',fnEnd,false)
            }
            box.addEventListener('touchmove',fnMove,false)
            box.addEventListener('touchend',fnEnd,false)
          },false)

    }
    </script>
</head>
<body>
    <div class="touchBox"></div>
</body>
</html>